package com.beagle.njddapp.ui.activity.owner;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.beagle.njddapp.R;
import com.beagle.njddapp.base.BaseMvpActivity;
import com.beagle.njddapp.bean.MessageBean;
import com.beagle.njddapp.ui.presenter.MessageDetailPresenter;
import com.beagle.njddapp.ui.view.MessageDetailView;
import com.beagle.njddapp.utils.StatusBarUtil;
import com.blankj.utilcode.util.ToastUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author hxx
 * @date 2021-03-19 21:46
 * 消息详情
 */
public class MessageDetailActivity extends BaseMvpActivity<MessageDetailView, MessageDetailPresenter> implements MessageDetailView {


    @BindView(R.id.commom_title_tv)
    TextView tvTitle;
    @BindView(R.id.common_container)
    RelativeLayout container;
    @BindView(R.id.common_tv_right)
    TextView tvRight;
    @BindView(R.id.tv_time)
    TextView tvtime;
    @BindView(R.id.tv_desc)
    TextView tvDesc;
    @BindView(R.id.iv_cover)
    ImageView ivCover;
    @BindView(R.id.rl_caocuo)
    RelativeLayout rlCaoZUo;
    @BindView(R.id.ll_caozup)
    LinearLayout llCaozuo;
    @BindView(R.id.tv_ok)
    TextView tvOk;

    private MessageBean messageBean;

    @Override
    public int getLayoutId() {
        return R.layout.activity_message_deatil;
    }

    @Override
    public void init() {
        StatusBarUtil.immersive(this);
        StatusBarUtil.darkMode(this);
        StatusBarUtil.setPaddingSmart(this,container);
        container.setBackgroundColor(Color.WHITE);
        tvTitle.setText("消息详情");
        messageBean= (MessageBean) getIntent().getSerializableExtra("data");
        if (messageBean==null){
            finish();
            return;
        }
        tvDesc.setText(messageBean.getDesc());
        tvtime.setText(messageBean.getRecieveTime());
        if ("common".equals(messageBean.getMessageType())){
            ivCover.setImageResource(R.mipmap.message_ic_orderstatus);
        }else {
            rlCaoZUo.setVisibility(View.VISIBLE);
            ivCover.setImageResource(R.mipmap.message_ic_refuelingorder);
            if ("accept".equals(messageBean.getMessageDealData())){
                tvOk.setVisibility(View.VISIBLE);
            }else if ("refuse".equals(messageBean.getMessageDealData())){
                tvOk.setVisibility(View.VISIBLE);
                tvOk.setText("已拒绝");
            }else {
                llCaozuo.setVisibility(View.VISIBLE);
            }
        }
        messageBean.setReaded(true);
        int[] ids=new int[1];
        ids[0]=messageBean.getId();
        presenter.read(ids);

    }

    @Override
    public MessageDetailView getMvpView() {
        return this;
    }

    @Override
    public MessageDetailPresenter createPresenter() {
        return new MessageDetailPresenter();
    }

    @Override
    public void onError(String message) {
        ToastUtils.showShort(message);
    }


    @OnClick({R.id.common_back_iv, R.id.tv_refuse, R.id.tv_accept})
    public void onCLick(View view) {
        switch (view.getId()) {
            case R.id.common_back_iv:
                onBackPressed();
                break;
            case R.id.tv_refuse:
                presenter.dela(messageBean.getId(),"refuse");

                break;
            case R.id.tv_accept:
                presenter.dela(messageBean.getId(),"accept");
                break;


        }
    }

    @Override
    public void dealSuccess(String caozup) {
        ToastUtils.showShort("操作成功");
        messageBean.setMessageDealData(caozup);
        llCaozuo.setVisibility(View.GONE);
        if ("refuse".equals(caozup)){
            tvOk.setVisibility(View.VISIBLE);
            tvOk.setText("已拒绝");
        }else {
            tvOk.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onBackPressed() {
        Intent intent=new Intent();
        intent.putExtra("data",messageBean);
        setResult(305,intent);
        finish();
    }
}
